﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Manager.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="B2B.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">



</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HEAD" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="main_content" runat="server">

    <script type="text/javascript">

        function Inbox() {
                $("#divInBox").css("display", "inline");
                $("#divSentBox").css("display", "none");
        }

        function Sentbox() {
            
                $("#divInBox").css("display", "none");
                $("#divSentBox").css("display", "inline");         
        }

        function DeleteSentBox(maEmail) {
            var r = confirm("Do you want to delete this email?");
            if(r==true){
                $.getJSON("/Manage/DeleteMessage?maMessage="+ maEmail,function(data){
                    if(data == 1){
                        $("#tblSentBox tr#tr" + maEmail).remove();
                    }else
                        alert("You can't delete this email");
                });

                
            }
            
        }
        function DeleteInbox(maEmail) {
            var r = confirm("Do you want to delete this email?");
            if(r == true){
                $.getJSON("/Manage/DeleteMessage?maMessage="+ maEmail,function(data){
                    if(data == 1){
                        $("#tblInBox tr#tr" + maEmail).remove();
                    }else
                        alert("You can't delete this email");
                });
               
            }
        }

    </script>
    <h6> Management -> Messages & Contact</h6>
      <div id="trigger-info">
        <input type="button"class="trigger error-trigger" value="Inbox" onclick="Inbox()"/> 
        <input type="button"class="trigger error-trigger" value="Sendbox" onclick="Sentbox()"/> 
    </div>
    <!--Bat dau hop thu inbox-->
    <div id="divInBox" style="display:inline">
        <table id="tblInBox" cellpadding="10px" border="1">
            <tr style="background-color:#177f75; font-size:20px; color:white">
                <th>Xóa </th>
                <th style="width:200px">Sender</th>
                <th style="width:400px">Subject</th>
                <th style="width:100px">Date</th>
            </tr>
            <%
                int i = 0;
              foreach (var mailInbox in (ArrayList)ViewData["dsMailInbox"])
              {
                  string maEmail = ((SP_EmailInbox)mailInbox).MaEmail.ToString();
                  string sender = ((SP_EmailInbox)mailInbox).HoTen;
                  string subject =((SP_EmailInbox)mailInbox).ChuDe;
                  string date = ((SP_EmailInbox)mailInbox).NgayGui.ToShortDateString();
                  if(i % 2 ==0)
                  {
            %>           
             <tr id="tr<%=maEmail %>" style="background-color:#d1bff0; font-size:15px">
             <!--   <td><a style="color:black" href="/Manage/DeleteMessage/<%=maEmail %>">Delete</a></td>-->
                 <td><input type="button" onclick="DeleteInbox(<%=maEmail%>)" value="Delete" class="btn" /></td>
                <td><a style="color:black" href="/Manage/MessageInbox/<%=maEmail %>"><%=sender %></a></td>
                <td><a style="color:black" href="/Manage/MessageInbox/<%=maEmail %>"><%=subject %></a></td>
                <td><a style="color:black" href="/Manage/MessageInbox/<%=maEmail %>"><%=date %></a></td>               
            </tr>
                <%
                } 
                else{
                %>
            <tr id="tr<%=maEmail %>" style="font-size:15px">
              <!--  <td><a href="/Manage/DeleteMessage/<%=maEmail %>">Delete</a></td>-->
                  <td><input type="button" onclick="DeleteInbox(<%=maEmail%>)" value="Delete" class="btn" /></td>
                <td><a href="/Manage/MessageInbox/<%=maEmail %>"><%=sender %></a></td>
                <td><a href="/Manage/MessageInbox/<%=maEmail %>"><%=subject %></a></td>
                <td><a href="/Manage/MessageInbox/<%=maEmail %>"><%=date %></a></td>               
            </tr>
            <%
                } 
              i++;
            %>
                 
            <%} %>      
        </table>
    </div>
    <!--Kết thúc hộp thư inbox-->

    <!--Bắt đầu hộp thư sentbox-->
    <div id="divSentBox" style="display:none">
        <table id="tblSentBox" cellpadding="10px" border="1">
            <tr style="background-color:#177f75; font-size:20px; color:white">
                <th>Xóa</th>
                <th style="width:200px">Sender</th>
                <th style="width:400px">Subject</th>
                <th style="width:100px">Date</th>
            </tr>
            <%
                int j = 0;
                foreach (var sentMail in (ArrayList)ViewData["dsMailSent"])
                {
                    string maEmail = ((SP_SentEmail)sentMail).MaEmail.ToString();
                    string sender = ((SP_SentEmail)sentMail).HoTen;
                    string subject = ((SP_SentEmail)sentMail).ChuDe;
                    string date = ((SP_SentEmail)sentMail).NgayGui.ToShortDateString();
                    if(j % 2 == 0)
                    {
            %>
             <tr id="tr<%=maEmail %>" style="background-color:#d1bff0; font-size:15px">
               <!-- <td><a style="color:black" href="/Manage/DeleteMessage/<%=maEmail %>">Delete</a></td>-->
                   <td><input type="button" onclick="DeleteSentBox(<%=maEmail%>)" value="Delete" class="btn" /></td>
                <td><a style="color:black" href="/Manage/MessageSentBox/<%=maEmail %>"><%=sender %></a></td>
                <td><a style="color:black" href="/Manage/MessageSentBox/<%=maEmail %>"><%=subject %></a></td>
                <td><a style="color:black" href="/Manage/MessageSentBox/<%=maEmail %>"><%=date %></a></td>               
            </tr> 
            <%}
              else
              { %>
                <tr id="tr<%=maEmail %>" style="font-size:15px">
                  <!--  <td><a href="/Manage/DeleteMessage/<%=maEmail %>">Delete</a></td>-->
                      <td><input type="button" onclick="DeleteSentBox(<%=maEmail%>)" value="Delete" class="btn" /></td>
                    <td><a href="/Manage/MessageSentBox/<%=maEmail %>"><%=sender %></a></td>
                    <td><a href="/Manage/MessageSentBox/<%=maEmail %>"><%=subject %></a></td>
                    <td><a href="/Manage/MessageSentBox/<%=maEmail %>"><%=date %></a></td>               
                </tr> 
            <%} j++;%>

            <%} %>          
        </table>
    </div>
    <!--Kết thúc hộp thư sentbox-->
</asp:Content>
